import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-03-16
 * Time: 16:31
 */
public class JDBCDemo4 {
    public static void main(String[] args) throws SQLException {
        /**
         * 修改表中的内容
         */
        //1.建立数据源
        DataSource dataSource=new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl
                ("jdbc:mysql://127.0.0.1:3306/java111?characterEncoding=utf8&useSSL=false");


        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("11111111");
        //2.建立连接
        Connection connection=dataSource.getConnection();
        //3.构造 一个操作数据库的sql
        String sql = "update student set id=4 where name='李四'";
        PreparedStatement preparedStatement=connection.prepareStatement(sql);
        //4.执行sql
        int  n=preparedStatement.executeUpdate();
        System.out.println("n=" +n);
        //5.释放资源
        preparedStatement.close();
        connection.close();

    }
}
